package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;

	@GetMapping(value = "/findUserInfoById/{userId}")
	public Result<UserInfo> findUserInfoById(@PathVariable(value = "userId") Long userId) {
		UserInfo userInfo = userInfoService.getById(userId);
		return Result.ok(userInfo) ;
	}


	@GuiguLogin
	@GetMapping(value = "/findUserInfoVoByUserId/{userId}")
	public Result<UserInfoVo> findUserInfoVoByUserId(@PathVariable(value = "userId") Long userId) {
		UserInfoVo userInfoVo = userInfoService.findUserInfoVoByUserId(userId) ;
		return Result.ok(userInfoVo) ;
	}

	/**
	 * Map中封装了响应结果数据
	 * Map的键表示的就是声音的id
	 * Map的值表示的就是是否购买的标记，如果是0表示没有购买过，如果是1表示购买过
	 */
	@GuiguLogin
	@PostMapping(value = "/userIsPaidTrack/{albumId}")
	public Result<Map<Long , Integer>> userIsPaidTrack(@PathVariable(value = "albumId") Long albumId , @RequestBody List<Long> trackIds) {
		Map<Long , Integer> result = userInfoService.userIsPaidTrack(albumId , trackIds) ;
		return Result.ok(result) ;
	}

	@GuiguLogin
	@GetMapping(value = "/findUserPaidTrackList/{albumId}")
	public Result<List<Long>> findUserPaidTrackList(@PathVariable(value = "albumId") Long albumId) {
		List<Long> userPaidTrackList =  userInfoService.findUserPaidTrackList(albumId) ;
		return Result.ok(userPaidTrackList) ;
	}



}

